<template>
  <div class="ChildPage TablePage">
    <vb-table :option="option" ref="table"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @on-load="getList">
    </vb-table>
  </div>
</template>

<script>
  export default {
    mixins: [],
    components: {
    },
    data() {
      let self = this
      return {
        option: {
          selection: true,
          index: true,
          menuWidth: 200,
          column: [
            {
              label: "机构名称",
              prop: "name",
              search: {
                show: false,
                hiddenLabel: true,
                label: "关键词",
                prop: "name",
                placeholder: "\ue605 机构名称"
              },
              form: {
                rules: [
                  {
                    required: true,
                    trigger: "click"
                  }
                ],
              },
            },
            {
              label: "机构编码",
              prop: 'key',
              width: 150,
              form: {
                rules: [
                  {
                    required: true,
                    trigger: "click"
                  }
                ],
              },
            },
            {
              label: "机构全称",
              prop: 'fullName',
              form: {
                rules: [
                  {
                    required: true,
                    trigger: "click"
                  }
                ],
              },
            },
            {
              label: "机构类型",
              prop: 'type',
              type: "select",
              dicType: "dicKey",
              dicKey: "orgType",
              dicData: [],
              width: 150,
              form: {
                rules: [
                  {
                    required: true,
                    trigger: "click"
                  }
                ],
              },
            },
            {
              label: "机构排序",
              prop: "sort",
              type: "inputNumber",
              width: 80,
              align: "center",
              form: {
                default: 1,
                rules: [
                  {
                    required: true,
                    trigger: "click"
                  }
                ],
              },
            },
            {
              label: "上级机构",
              prop: 'parentIds',
              tableShow: false,
              type: "tree",
              dicData: [],
              treeProps: {
                checkStrictly: true,
                emitPath: false,
                label: "name",
                value: "id",
                multiple: true
              },
              form: {
                span: 24
              }
            },
            {
              label: "机构备注",
              prop: 'remark',
              type: "textarea",
              form: {
                span: 24,
              }
            }
          ],
          page: {
            show: false
          },
          form: {
            width: 800
          },
          handleBtnList: [
            {
              key: "edit"
            },
            {
              key: "delete"
            },
            {
              label: "添加子项",
              icon: "el-icon-circle-plus-outline",
              type: "text",
              callback: function (row) {
                self.addChild(row)
              }
            },
          ],
        }
      }
    },
    computed: {},
    async mounted() {
    },
    methods: {

      /**
       * 查询数据列表信息
       * @param page
       * @param search 检索条件
       * @param done
       */
      getList (page, size, search, done) {
        let self = this
        this.$api.getOrganList(Object.assign({
          pageIndex: page,
          pageSize: size
        }, search)).then(res => {
          res.data = self.$apiUtils.arrOrganList(res.data)
          self.$refs.table.setColumnDicDataByProp("parentIds", res.data)
          done(res)
        })
      },

      /**
       * 新增数据处理
       * @param form
       * @param done
       */
      rowSave (form, done) {
        this.$api.addOrgan(form).then((res) => {
          done(res)
        })
      },

      /**
       * 更新数据处理
       * @param form
       * @param done
       */
      rowUpdate (form, done) {
        this.$api.updateOrgan(form).then((res) => {
          done(res)
        })
      },

      /**
       * 删除数据处理
       * @param ids
       * @param done
       */
      rowDel (ids, done) {
        this.$api.deleteOrgan({
          ids: ids
        }).then((res) => {
          done(res)
        })
      },

      /**
       * 添加子项
       * @param row
       */
      addChild (row) {
        this.$refs.table.openDialog({
          parentIds: [row.id]
        })
      }
    },
    watch: {
    }
  }
</script>

<style lang="scss" scoped>
</style>
